<?php

namespace App\Command\Tests;

use App\Lib\Rooms\Services\RoundsService;
use App\Model\RoomsModel;
use App\Model\RoundsModel;
use App\Model\UsersModel;
use Hyperf\Command\Annotation\Command;
use Hyperf\Di\Annotation\Inject;

/**
 * @Command()
 * Class RoundTests
 * @package App\Command\Tests
 */
class RoundTests extends BaseTests
{
    protected $name = 'test:round';


    /**
     * @Inject()
     * @var RoundsService
     */
    protected $roundsService;


    /**
     * 1、创建回合
     */
    protected function create()
    {
        /** @var RoomsModel $room */
        $room = RoomsModel::query()->find(1);
        $ids = [];
        for ($i = 1; $i < $room->number; $i++) {
            $user = UsersModel::query()->find($i + 1);
            $ids[] = $user->id;
        }
        $rounds = $this->roundsService->create($room, $ids);
        dump($rounds);
    }

    /**
     * 2、洗牌
     * @throws \App\Lib\_Error\ExecuteException
     * @throws \App\Lib\_Error\ValidateException
     */
    protected function shuffle()
    {
        /** @var RoundsModel $round */
        $round = RoundsModel::query()->first();
        $round = $this->container->get(RoundsService::class)->shuffleCards($round);
        dump($round);
    }

    /**
     * 3、骰子
     * @throws \App\Lib\_Error\ExecuteException
     * @throws \App\Lib\_Error\ValidateException
     */
    protected function touzi()
    {
        /** @var RoundsModel $round */
        $round = RoundsModel::query()->first();
        $round = $this->container->get(RoundsService::class)->touZi($round);
        dump($round);
    }

    /**
     * 4、发牌
     * @throws \App\Lib\_Error\ExecuteException
     * @throws \App\Lib\_Error\ValidateException
     */
    protected function deal()
    {
        /** @var RoundsModel $round */
        $round = RoundsModel::query()->first();
        $round = $this->container->get(RoundsService::class)->dealCards($round);
        dump($round);
    }

    /**
     * 5、马牌
     * @throws \App\Lib\_Error\ExecuteException
     * @throws \App\Lib\_Error\ValidateException
     */
    protected function ma()
    {
        /** @var RoundsModel $round */
        $round = RoundsModel::query()->first();
        $round = $this->container->get(RoundsService::class)->dealMaCards($round);
        dump($round);
    }
}